Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Glint types by converting helpers to plain functions #188

Merged
merged 19 commits into from
Sep 2, 2023

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Aug 28, 2023

@SergeAstapov
Copy link
Collaborator

@NullVoxPopuli thanks for submitting this! Do you see this solve any TS issues we tried to solve and couldn't in #185?

@NullVoxPopuli
Copy link
Contributor Author

perhaps!
image

@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review August 28, 2023 18:56
@NullVoxPopuli NullVoxPopuli mentioned this pull request Aug 28, 2023
Comment on lines 12 to 17
for (let i = 0, len = params.length; i < len; i++) {
if (truthConvert(params[i]) === false) {
return params[i] as boolean;
}
}
return params[params.length - 1] as boolean;
Copy link
Contributor

@Techn1x Techn1x Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping the as boolean's here might not quite meet the type needs of #185 for the and helper

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not that this PR needs to solve that too)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'd prefer to add tests for the scenarios in #185 -- but in a separate PR -- since this PR is mostly a mechanical change branched off of #185, I'd prefer to iterate, so that PRs can remain reviewable

@@ -16,7 +16,7 @@
"scripts": {
"build": "concurrently 'npm:build:*'",
"build:js": "rollup --config",
"build:types": "glint --declaration && grep -r -l '///' declarations/ | sort | uniq | xargs perl -e \"s/\\/\\/\\/.*$//\" -pi",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fixed

Copy link
Contributor

@gossi gossi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Thanks for finishing my work and turning these into pure functions ❤️

@SergeAstapov
Copy link
Collaborator

@NullVoxPopuli and other who follow: I tried to bump this in our app (via https://github.com/jmurphyau/ember-truth-helpers/tree/helpers-as-plain-functions-dist) and see many of tests fail, will look into root cause why behavior is different.

Glint and TS were happy though.

@NullVoxPopuli
Copy link
Contributor Author

I tried to bump this in our app

do you have a reproduction?

@SergeAstapov
Copy link
Collaborator

I tried to bump this in our app

do you have a reproduction?

sorry, it's behind VPN. I'm digging what exactly is the issue and if it's our app code or the lib code issue

}

export default helper<AndSignature>((params) => {
export default function and<T extends MaybeTruth[]>(...params: [...T]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NullVoxPopuli using spread causes an issue - today, arguments gets lazily evaluated and spread makes it process eager.

e.g. imagine use case

{{and (foo "A") (bar "B")}}

today, if (foo "A") returns false, then (bar "B") does not get evaluated.
but this line change makes it evaluated which is definitely not what we want

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make or lazy or short-circuit, it needs to be built in to the VM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if or and and need to remain "classic" I wonder if that means converting to class helpers so that we can correctly use generics?

}

export default helper<OrSignature>((params) => {
export default function or<T extends MaybeTruth[]>(...params: [...T]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue here as in and helper

that way, we preserve semantic of them lazily evaluating arguments and able to accept generics
@SergeAstapov SergeAstapov changed the title Convert helpers to normal functions. Fix Glint types by converting helpers to plain functions Sep 2, 2023
@NullVoxPopuli
Copy link
Contributor Author

Made a tool to help out in the future: https://github.com/NullVoxPopuli/fix-bad-declaration-output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect glint return type for or helper in 4.0.0-beta.0
4 participants